package com.imau.service.impl;

import com.imau.bean.User;
import com.imau.common.SqlSessionFactoryUtil;
import com.imau.mapper.UserMapper;
import com.imau.service.UserService;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class UserServiceImpl implements UserService {

    private UserMapper userMapper;

    /**
     * 查询用户
     * @param userName
     * @return
     */
    @Override
    public User getUser(String userName) {

        SqlSessionFactory factory = SqlSessionFactoryUtil.getInstace();
        //1.获取SqlSessionFactory 2分
        SqlSession session = factory.openSession(true);
        //2.获取SqlSession 2分
        userMapper = session.getMapper(UserMapper.class);
        //3.获取UserMapper 2分
        User user =  userMapper.getByUserName(userName);
        //4.调用持久化userMapper中方法getuserName 2分

        session.close();
      //5.返回结果 2分
        return user;
    }
}
